package com.lbb.shard.jdbc.demo.controller;

import com.lbb.shard.jdbc.demo.pojo.Order;
import com.lbb.shard.jdbc.demo.servicer.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

@RestController
public class DemoController {

    @Autowired
    public OrderService orderService;

    @GetMapping("/queryUserIdByOrderId/{orderId}")
    public String queryOrder(@PathVariable("orderId") Integer orderId){
        List<Order> byUserId = orderService.findByUserId(orderId);
        return byUserId.size() == 0 ? "不存在":byUserId.get(0).getUserId();
    }

    @GetMapping("/saveOrder")
    public void saveOrder(){
        for (int i = 0; i < 10; i++) {
            Order order = new Order();
            order.setUserId("zs_"+i);
            order.setTotalPrice(100.0);
            order.setOrderId(Long.parseLong(i+""));
            order.setCreateTime(new Date());
            orderService.SaveOrder(order);
        }
    }




}
